package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.domain.customer.CustomerDO;
import com.qk.entity.Customer;
import com.qk.entity.dto.customer.CustomerListDTO;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fantuan
 * @created 2025/10/16 17:15
 * @description
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomerById(@RequestBody Customer customer){
        customerService.updateCustomerById(customer);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id){
        Customer customer = customerService.selectById(id);
        return Result.success(customer);
    }

    @PostMapping
    public Result addCustomer(@RequestBody Customer customer) {
        customerService.addCustomer(customer);
        return Result.success();
    }

    @GetMapping
    public Result list(CustomerListDTO dto){
        PageResult<CustomerDO> pageResult =  customerService.customerList(dto);
        return Result.success(pageResult);
    }
}
